#version 130

uniform mat4 matrix_projection;
uniform mat4 matrix_world;
uniform mat4 matrix_view;

uniform mat4 matrix_shadow0;
uniform mat4 matrix_shadow1;
uniform mat4 matrix_shadow2;

uniform mat4 matrix_bones[64];

in vec4 vertices;
in ivec4  bones;
in vec4 bone_blends;

out vec4 pos[3];


vec4 eval_skeleton_vector (ivec4 bones, vec4 blends, vec4 vec)
{
	return
		(matrix_bones[bones.x] * vec) * blends.x +
		(matrix_bones[bones.y] * vec) * blends.y +
		(matrix_bones[bones.z] * vec) * blends.z +
		(matrix_bones[bones.w] * vec) * blends.w;
}


void main(void)
{
	vec4 global_pos = matrix_world * eval_skeleton_vector (bones, bone_blends, vertices);
	pos[0] = matrix_shadow0 * global_pos;
	pos[1] = matrix_shadow1 * global_pos;
	pos[2] = matrix_shadow2 * global_pos;

	gl_Position = matrix_projection * matrix_view * global_pos;
}
